<template>
	<view class="loading" :class="{zIndex:show}" @touchmove.prevent>
		<view class="mask" :style="{transition: 'opacity ' + time + ' ease-out'}" :class="{active:show}">
			<image :src="image" mode="" v-if="show" lazy-load="true"></image>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				// time:'.2s', // 蒙层的动画时间
				show:false,// 是否显示蒙层
				image:"/static/loading/loading.gif"
			}
		},
		props:{
			time:{
				type:String,
				default(){
					return '0.3s'
				}
			}
		},
		methods:{
			// 打开loading
			open(){
				this.show = true
			},
			// 关闭loading
			close(){
				this.show = false
			},
		}
	}
</script>

<style scoped>
	.loading {
		position: fixed;
		top: var(--window-top);
		bottom: 0;
		left: 0;
		right: 0;
		overflow: hidden;
		z-index: -999;
	}
	.mask{
		position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		background-color: rgba(0, 0, 0, 0.4);
		opacity: 0;
		visibility: hidden;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.active{
		opacity: 1;
		visibility: visible;
	}
	.zIndex{
		z-index: 999;
	}
	.mask image{
		width: 160rpx;
		height: 160rpx;
		border-radius: 50%;
	}
</style>
